﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.ComponentModel.DataAnnotations;
using System.Globalization;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using System.Web.Security;

namespace GabageFactory.Models
{
    public class StackBackWaterReposity : Reposity
    {
        public stack_backwater_info GetDailyBackWaterInfo(int stackId, DateTime date)
        {
            var dailyBackWater = from s in _dataContext.stack_backwater_infos
                             where stackId == s.stack_id && s.date == date.Date
                             select s;

            if (dailyBackWater != null && dailyBackWater.Count() > 0)
            {
                return dailyBackWater.First();
            }
            else
            {
                return null;
            }
        }

        public stack_backwater_info CreateBackWaterInfo(stack_backwater_info backWaterInfo)
        {
            _dataContext.stack_backwater_infos.InsertOnSubmit(backWaterInfo);
            SubmitChanges();
            return backWaterInfo;
        }

        public bool DeleteWaterInfo(stack_backwater_info backWaterInfo)
        {
            _dataContext.stack_backwater_infos.DeleteOnSubmit(backWaterInfo);
            return true;
        }
    }
}